home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
jaz_clib.arc
/
RENFILE.DMO
< prev
next >
Wrap
Text File
|
1989-04-09
|
2KB
|
53 lines
#include <jzdirect.h>
main(argc,argv)
int argc;
char **argv;
{
/* various work variables */
int werr,wrenerr,w;
TDIR wdir;
char woldpath[50],wnewpath[50],woldname[100],wnewname[100];
char wspec[50];
if (argc != 3) { /* not enough args */
printf("\nRENFILE by Jack A. Zucker @794-5950 | 794-8763 | 937-9500");
printf("\nThis program allows renaming files across subdirectories");
printf("\nbut unlike previous versions, accepts wildcards");
printf("\nUSAGE: renfile <old path\\old name> <new path>");
exit(1);
}
strcpy(woldpath,argv[1]); /* parse out path from old file name */
w = rindex(woldpath,'\\'); /* see if there is a path specified */
woldpath[++w] = '\0'; /* woldpath now contains only the path */
strcpy(wspec,argv[1]+w); /* wspec contains only the file spec */
strcpy(wnewpath,argv[2]); /* get new name */
w = rindex(wnewpath,'\\'); /* look for and get rid of trailing '/'*/
if (w == (strlen(wnewpath)-1)) /* new name ends in '/' */
wnewpath[w] = 0; /* get rid of '/' */
werr = jzfndfst(argv[1],32,&wdir); /* start directory search */
if (! werr) /* zero indicates we got a dir item */
do {
strcpy(woldname,woldpath); /* concatenate wdir.name to path */
strcat(woldname,wdir.name);
strcpy(wnewname,wnewpath);
strcat(wnewname,"\\");
strcat(wnewname,wdir.name); /* put file name at end of dest dir */
if (rename(wnewname,woldname)) {
printf("\n%s could not be renamed to %s",woldname,wnewname);
werr = jzfndnxt(&wdir); /* on error skip this item */
}
/* since we effectively deleted this item, the next directory */
/* search must begin from the beginning, not the next item !! */
else {
printf("\n%s renamed to %s",woldname,wnewname);
werr = jzfndfst(argv[1],32,&wdir);
}
} while (! werr);
}